package com.snopy.designPattern.filter.impl;

import com.snopy.designPattern.filter.bean.Person;
import com.snopy.designPattern.filter.inter.Criteria;

import java.util.List;

/**
 * @author snopy
 * @version 1.0.0
 * @classname OrCriteria
 * @description
 * @email 77912204@qq.com
 * @date 2022/03/03 10:02
 */
public class OrCriteria implements Criteria {
    private Criteria criteria;
    private Criteria otherCriteria;

    public OrCriteria(Criteria criteria, Criteria otherCriteria) {
        this.criteria = criteria;
        this.otherCriteria = otherCriteria;
    }

    @Override
    public List<Person> meetCriteria(List<Person> persons) {
        List<Person> list = criteria.meetCriteria(persons);
        List<Person> list1 = otherCriteria.meetCriteria(persons);
        for (Person p1:list) {
            if (!list1.contains(p1)){
                list1.add(p1);
            }
        }
        return list1;
    }
}
